import json

import requests


class QQLogintool():
    def __init__(self, appid, secret, type, redirect_uri):
        self.appid = appid
        self.secret = secret
        self.type = type
        self.redirect_uri = redirect_uri
        self. base_url = "https://u.rechen.site/connect.php"

    def get_qq_url(self):

        params = {
            'act': 'login',
            'appid': self.appid,
            'appkey': self.secret,
            'type': self.type,
            "redirect_uri": self.redirect_uri
        }
        response = requests.get(self.base_url, params=params)
        json_code = json.loads(response.text)
        return json_code['url']
    def get_access_token(self,code):
        #  act=callback&appid={appid}&appkey={appkey}&type={登录方式}&code={code}

        params = {
            'act': 'callback',
            'appid': self.appid,
            'appkey': self.secret,
            'type': self.type,
            "code":code
        }
        response = requests.get(self.base_url, params=params)
        json_code = json.loads(response.text)
        print(json_code)
        return json_code



if __name__ == '__main__':
    q = QQLogintool(appid="1017",secret="51a30f3269f87733dcfeb6baf7015cc7",type="qq",redirect_uri="http://www.meiduo.com/collback")
   # q.get_qq_url()
    q.get_access_token("A681D3BCEF16BA1A0E6846EF7168CCCC")
